home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / criterrc / criterr.lst < prev    next >
File List  |  1991-02-16  |  15KB  |  332 lines

  1. Turbo Assembler     Version 2.0        02/17/91 12:40:52        Page 1
  2. criterr.asm
  3. CRITERR.ASM
  4. TRAP CRITICAL ERRORS FROM W/IN C
  5.  
  6.       1
  7.       2
  8.       3                     ; MODULE CRITERR.ASM
  9.       4                     ; JANUARY 1991
  10.       5                     ; PETER HYMAN (609) 799-2638
  11.       6                     ; 148 TENNYSON DRIVE
  12.       7                     ; PLAINSBORO, NJ  08536
  13.       8
  14.       9                     ; MODIFIED    2/16/91    SEE NOTES AT END OF SOURCE FOR DESCRIPTION OF CHANGES
  15.      10
  16.      11                     ;;;;; TWO FUNCTIONS ;;;;;
  17.      12
  18.      13                     ; FUNCTION    NAME:  CRITERR(    ONOFF )
  19.      14                     ; INPUTS 1    = TRAP CRITICAL    ERRORS,    0 TURN OFF TRAP
  20.      15                     ; RETURNS 0 IF SUCCESSFUL,    1 IF ALREADY INSTALLED
  21.      16
  22.      17                     ; FUNCTION    NAME:  CLRCRITERR( )
  23.      18                     ; CLEAR CRITICAL ERROR VARIABLES
  24.      19
  25.      20                     ; ON CRITICAL ERRORS, INT 24H HANDLER WILL    RETURN AN IGNORE CODE TO DOS
  26.      21                     ; IF VERSION < 3, OR A FAIL CODE FOR DOS >= 3
  27.      22                     ; IF VERSION >= 3,    DOS FUNCTION 59H IS CALLED ALSO, AND EXTENDED ERROR
  28.      23                     ; INFO IS ALSO PUT    INTO STRUCTURE
  29.      24
  30.      25                     ;;;;; USES    SIMPLIFIED SEGMENT DIRECTIVES.    ASSEMBLE WITH I8086S, M, C OR L
  31.      26                     ;;;;; DEFINED
  32.      27
  33.      28                     ;;;;; ASSEMBLE AS MASM/TASM /mx /dI8086[S|M|C|L] criterr;
  34.      29                     ;;;;; TURBO ASSEMBLER YIELDS SMALLER CODE WITH /Q OPTION
  35.      30
  36.      31    0000                         .MODEL  LARGE
  37.      32          =    0006                     p equ 6
  38.      33          =    0001                     LCODE EQU 1
  39.      34          =    0001                     LDATA EQU 1
  40.      35
  41.      36                     ;;;;; FORMAT FOR CRITICAL ERROR  HEADER BLOCK ;;;;;
  42.      37                     ;;;;; CERTAIN CHAR    VARIABLES EXPANDED TO INT FOR PROPER ALLIGNMENT    ;;;;;
  43.      38    *000                 CERR         STRUC   ; critical    error structure
  44.      39    *000  01*(??)             ceflag         db      ?  ; flag to indicate    critical error 1 = yes
  45.      40    *001  01*(??)             cerrno         db      ?  ; critical    error number  ;    2/16/91    changed    to byte
  46.      41    *002  01*(????)             cerrtype         dw      ?  ; critical    error type/action/drive, AX
  47.      42    *004  01*(??)             drive         db      ?  ; drive letter as a char
  48.      43    *005  01*(??)             read_wr         db      ?  ; read or write error 1 = write
  49.      44    *006  01*(??)             disk_area         db      ?  ; area of error, 0    = dos area, 1 =    fat, 2 = dir, 3    = data
  50.      45    *007  01*(??)             resp_mask         db      ?  ; allowable responses (moot)
  51.      46    *008  01*(??)             exterr         db      ?  ; extended    error number  DOS >= 3 2/16/91 changed to byte
  52.      47    *009  01*(??)             eclass         db      ?  ; error class
  53.      48    *00A  01*(??)             action         db      ?  ; action recommendations
  54.      49    *00B  01*(??)             locus         db      ?  ; locus
  55.      50    *00C  01*(????????)         nextdev         dd      ?  ; next device pointer
  56.      51    *010  01*(????)             attr         dw      ?  ; device attribute
  57.      52    *012  01*(????)             nxtfunc         dw      ?  ; pointer to next strategy    function
  58.      53    *014  01*(????)             intfunc         dw      ?  ; pointer to interrupt function
  59.      54    *016  01*(08*(??))         devname         db      8 dup(?)   ; device name
  60.      55    *01E  01*(??)             dummy         db      ?  ; terminating null
  61.      56    *01F                 CERR    ENDS
  62.      57
  63. Turbo Assembler     Version 2.0        02/17/91 12:40:52        Page 2
  64. criterr.asm
  65. CRITERR.ASM
  66. TRAP CRITICAL ERRORS FROM W/IN C
  67.  
  68.      58                     ; SEE DOS TECHNICAL REFERENCE FOR EXPLANATION OF CODES
  69.      59
  70.      60
  71.      61                     ;;;;; BEGIN DATA SEGMENT ;;;;;  USING SIMPLIFIED SEGMENT DIRECTIVES
  72.      62
  73.      63    0000                     .DATA             ; begin data segment
  74.      64                         extrn __osmajor:byte    ; operating system    version
  75.      65    0000  00             _criterrtrap    db    0         ; critical    error flag 1=trapped, 0    = off
  76.      66                     ;;;;;   GLOBAL  ;;;;;
  77.      67                         public _cerr         ; GLOBALS
  78.      68    0001  1F*(??)             _cerr   CERR <>             ; CRITICAL    ERROR STRUCTURE    BLOCK
  79.      69
  80.      70    0020                     .DATA?             ; uninitialized data
  81.      71    0000                 _oldint24vec    label  dword
  82.      72    0000  ????             _oldint24off    dw    ?         ; static vector to    int 24 before trap
  83.      73    0002  ????             _oldint24seg    dw    ?         ;
  84.      74
  85.      75
  86.      76                     ; PROCEDURE CRITERR( ONOFF    )
  87.      77                     ; SETS ALTERNATE CRITICAL ERROR HANDLER
  88.      78                     ; USAGE:         criterr( 1    ) to set, criterr( 0 ) to turn off
  89.      79
  90.      80    0004                     .CODE             ; begin code segment
  91.      81
  92.      82    0000  0000             savds   dw         0             ; save proper data    segment
  93.      83
  94.      84                         public _criterr
  95.      85    0002                 _criterr         proc    far
  96.      86    0002  55                 push bp
  97.      87    0003  8B EC                 mov bp, sp
  98.      88    0005  56                 push si
  99.      89    0006  57                 push di
  100.      90    0007  8B 46 06                 mov ax, p[bp]         ; see if a    0 or 1 was passed
  101.      91    000A  85 C0                 test ax, ax         ; non zero?
  102.      92    000C  75 1C                 jne settrap         ; 1, so set trap
  103.      93    000E                 removetrap:
  104.      94    000E  80 3E 0000r 01             cmp _criterrtrap, 1     ; see if installed
  105.      95    0013  75 45                 jne done             ; not installed, so return
  106.      96    0015  1E                 push ds
  107.      97    0016  C5 16 0000r             lds dx, _oldint24vec    ; restore original    int 24 vector
  108.      98    001A  B8 2524                 mov ax, 2524h
  109.      99    001D  CD 21                 int 21h             ; dos set vector function
  110.     100    001F  1F                 pop ds
  111.     101    0020  C6 06 0000r 00             mov _criterrtrap, 0     ; reset flag
  112.     102    0025  33 C0                 xor ax, ax             ; set return code
  113.     103    0027  EB 31 90                 jmp done
  114.     104    002A                 settrap:
  115.     105    002A  80 3E 0000r 01             cmp _criterrtrap, 1     ; see if installed
  116.     106    002F  74 29                 je     done             ; yes, so return (AX = 1)
  117.     107    0031  2E: 8C 1E    0000r             mov cs:savds, ds         ; move current data segment to savds
  118.     108    0036  06                 push    es
  119.     109    0037  B8 3524                 mov     ax,03524h         ; save old    vector to int 24
  120.     110    003A  CD 21                 int     021h
  121.     111    003C  89 1E 0000r             mov _oldint24off,bx
  122.     112    0040  8C 06 0002r             mov _oldint24seg,es
  123.     113    0044  07                 pop     es
  124.     114    0045  1E                 push    ds
  125. Turbo Assembler     Version 2.0        02/17/91 12:40:52        Page 3
  126. criterr.asm
  127. CRITERR.ASM
  128. TRAP CRITICAL ERRORS FROM W/IN C
  129.  
  130.     115    0046  BA 0065r                 mov     dx, offset    cs:int_service         ; load address of new routine
  131.     116    0049  8C C8                 mov     ax,cs
  132.     117    004B  8E D8                 mov     ds,ax
  133.     118    004D  B8 2524                 mov     ax,02524h         ; set it
  134.     119    0050  CD 21                 int     021h
  135.     120    0052  1F                 pop     ds
  136.     121    0053  C6 06 0000r 01             mov _criterrtrap, 1     ; set flag
  137.     122    0058  33 C0                 xor ax, ax             ;set return code
  138.     123
  139.     124    005A                 done:
  140.     125    005A  50                 push ax                 ; save AX
  141.     126    005B  0E E8 008C 90             call far ptr _clrcriterr         ; reset values
  142.     127    0060  58                 pop ax
  143.     128    0061  5F                 pop di
  144.     129    0062  5E                 pop si
  145.     130    0063  5D                 pop bp
  146.     131    0064  CB                 ret             ; return to caller, return    code in    AX
  147.     132
  148.     133
  149.     134                     ;;;;; NEW CRITICAL    ERROR HANDLER ;;;;;
  150.     135                     ;;;;; SEE DOS TECHNICAL REFERENCE ;;;;;
  151.     136
  152.     137    0065                 int_service:             ;int 24 trap goes here
  153.     138    0065  55                 push    bp
  154.     139    0066  8B EC                 mov     bp,sp         ; set to critical stack frame
  155.     140    0068  53                 push    bx             ; all used    registers except AX must be
  156.     141    0069  51                 push    cx             ; saved !!!!!
  157.     142    006A  52                 push    dx
  158.     143    006B  56                 push    si
  159.     144    006C  57                 push    di
  160.     145    006D  1E                 push    ds
  161.     146    006E  06                 push    es
  162.     147    006F  9C                 pushf
  163.     148    0070  2E: 8E 1E    0000r             mov     ds,cs:savds     ; reset ds    to program's ds
  164.     149    0075  8B DF                 mov     bx, di         ; save DI
  165.     150    0077  BF 0001r                 mov     di, offset    _cerr  ; set di    to point to structure cerr
  166.     151    007A  C6 05 01                 mov     ceflag[di], 1   ; set ceflag 2/16/91
  167.     152    007D  88 5D 01                 mov     cerrno[di], bl  ; move to cerrno -- move byte only    2/16/91
  168.     153    0080  89 45 02                 mov     cerrtype[di],ax ; save error type/drive number
  169.     154    0083  A9 8000                 test    ax, 8000h         ; char or block device
  170.     155    0086  8B D8                 mov     bx, ax
  171.     156    0088  75 10                 jnz     response         ; char device, so skip
  172.     157    008A  80 C3 41                 add     bl, 'A'         ; add letter A
  173.     158    008D  88 5D 04                 mov     drive[di],    bl   ; move drive over
  174.     159    0090  80 E7 06                 and     bh, 00000110b   ; leave only bits 1 and 2
  175.     160    0093  D0 EF                 shr     bh,1         ; shift it    over 1
  176.     161    0095  88 7D 06                 mov     disk_area[di], bh ; save area of error
  177.     162    0098  8A FC                 mov     bh, ah
  178.     163    009A                 response:                 ; determine response possibilities
  179.     164    009A  80 E7 01                 and     bh, 1         ; 2/16/91 this block moved    from prev para.
  180.     165    009D  88 7D 05                 mov     read_wr[di], bh ; move read write flag
  181.     166    00A0  8A FC                 mov     bh, ah
  182.     167    00A2  80 E7 38                 and     bh, 00111000b   ; leave only bits 3-5
  183.     168    00A5  D0 EF                 shr     bh,1
  184.     169    00A7  D0 EF                 shr     bh,1
  185.     170    00A9  D0 EF                 shr     bh,1         ; shift it    over
  186.     171    00AB  88 7D 07                 mov     resp_mask[di],bh ;    save response mask
  187. Turbo Assembler     Version 2.0        02/17/91 12:40:52        Page 4
  188. criterr.asm
  189. CRITERR.ASM
  190. TRAP CRITICAL ERRORS FROM W/IN C
  191.  
  192.     172    00AE                 move_dev_header:             ; move device header block
  193.     173    00AE  1E                 push    ds             ; set up data registers
  194.     174    00AF  07                 pop     es
  195.     175    00B0  8B 5E 00                 mov     bx,[bp]         ; load bp to get segment for device header
  196.     176    00B3  8E DB                 mov     ds,bx         ; si contains offset of device header
  197.     177    00B5  BF 000Dr                 mov     di,offset _cerr.nextdev ; copy device header block
  198.     178    00B8  FC                 cld
  199.     179    00B9  B9 0009                 mov     cx,9
  200.     180    00BC  F3> A5                 rep     movsw         ; move 18 bytes of    device header block
  201.     181    00BE  06                 push    es
  202.     182    00BF  1F                 pop     ds             ; restore data registers
  203.     183
  204.     184                         ; now check for DOS version
  205.     185    00C0  33 C0                 xor     ax,ax         ; return code ignore for dos < 3
  206.     186    00C2  80 3E 0000e 03             cmp     __osmajor,3     ; dos >= 3?
  207.     187    00C7  7C 18                 jl         doneint         ; no
  208.     188                         ; prepare to get extended error
  209.     189    00C9  BB 0000                 mov     bx, 0
  210.     190    00CC  B4 59                 mov     ah, 59h         ; get dos extended    error
  211.     191    00CE  CD 21                 int     21h         ; call dos
  212.     192    00D0  BF 0001r                 mov     di, offset    _cerr; set di to point to cerr structure
  213.     193    00D3  88 45 08                 mov     exterr[di], al  ; error code  -- move byte    only 2/16/91
  214.     194    00D6  88 7D 09                 mov     eclass[di], bh  ; error class
  215.     195    00D9  88 5D 0A                 mov     action[di], bl  ; action
  216.     196    00DC  88 6D 0B                 mov     locus[di],     ch  ; locus
  217.     197    00DF  B0 03                 mov     al, 3         ; return fail code
  218.     198    00E1                 doneint:
  219.     199    00E1  9D                 popf
  220.     200    00E2  07                 pop     es
  221.     201    00E3  1F                 pop     ds
  222.     202    00E4  5F                 pop     di
  223.     203    00E5  5E                 pop     si
  224.     204    00E6  5A                 pop     dx
  225.     205    00E7  59                 pop     cx
  226.     206    00E8  5B                 pop     bx
  227.     207    00E9  5D                 pop     bp             ; restore stack frame
  228.     208    00EA  CF                 iret             ; return from interrupt
  229.     209    00EB                 _criterr         endp
  230.     210
  231.     211                     ;;;;;   FUNCTION TO CLEAR CRITICAL    ERROR STATUS ;;;;;
  232.     212
  233.     213                     ;;;;; USAGE:  clrcriterr()
  234.     214
  235.     215                         public _clrcriterr
  236.     216    00EB                 _clrcriterr     proc   far         ; function    to clear critical error    number
  237.     217
  238.     218    00EB  55                 push bp
  239.     219    00EC  8B EC                 mov bp,sp
  240.     220    00EE  57                 push di
  241.     221    00EF  1E                 push ds
  242.     222    00F0  07                 pop es
  243.     223    00F1  33 C0                 xor ax,ax             ; zero entire structure
  244.     224    00F3  BF 0001r                 mov di, offset _cerr
  245.     225    00F6  B9 001F                 mov cx, size _cerr         ; get size    of entire block
  246.     226    00F9  F3> AA                 rep stosb
  247.     227    00FB  5F                 pop di
  248.     228    00FC  5D                 pop bp
  249. Turbo Assembler     Version 2.0        02/17/91 12:40:52        Page 5
  250. criterr.asm
  251. CRITERR.ASM
  252. TRAP CRITICAL ERRORS FROM W/IN C
  253.  
  254.     229    00FD  CB                 ret
  255.     230    00FE                 _clrcriterr     endp
  256.     231
  257.     232                     end
  258. Turbo Assembler     Version 2.0        02/17/91 12:40:52        Page 6
  259. Symbol Table
  260. CRITERR.ASM
  261.  
  262.  
  263.  
  264. Symbol Name              Type     Value
  265.  
  266. ??DATE                  Text     "02/17/91"
  267. ??FILENAME              Text     "criterr "
  268. ??TIME                  Text     "12:40:51"
  269. ??VERSION              Number 0200
  270. @CODE                  Text     CRITERR_TEXT
  271. @CODESIZE              Text     1
  272. @CPU                  Text     0101H
  273. @CURSEG                  Text     CRITERR_TEXT
  274. @DATA                  Text     DGROUP
  275. @DATASIZE              Text     1
  276. @FILENAME              Text     CRITERR
  277. @MODEL                  Text     5
  278. @WORDSIZE              Text     2
  279. DONE                  Near     CRITERR_TEXT:005A
  280. DONEINT                  Near     CRITERR_TEXT:00E1
  281. I8086L                  Text
  282. INT_SERVICE              Near     CRITERR_TEXT:0065
  283. LCODE                  Number 0001
  284. LDATA                  Number 0001
  285. MOVE_DEV_HEADER              Near     CRITERR_TEXT:00AE
  286. P                  Number 0006
  287. REMOVETRAP              Near     CRITERR_TEXT:000E
  288. RESPONSE              Near     CRITERR_TEXT:009A
  289. SAVDS                  Word     CRITERR_TEXT:0000
  290. SETTRAP                  Near     CRITERR_TEXT:002A
  291. _CERR (_cerr)              Struct DGROUP:0001 CERR
  292. _CLRCRITERR (_clrcriterr)      Far     CRITERR_TEXT:00EB
  293. _CRITERR (_criterr)          Far     CRITERR_TEXT:0002
  294. _CRITERRTRAP              Byte     DGROUP:0000
  295. _OLDINT24OFF              Word     DGROUP:0000
  296. _OLDINT24SEG              Word     DGROUP:0002
  297. _OLDINT24VEC              Dword     DGROUP:0000
  298. __OSMAJOR (__osmajor)          Byte     DGROUP:---- Extern
  299.  
  300. Structure Name              Type    Offset
  301.  
  302. CERR
  303.  CEFLAG                  Byte     0000
  304.  CERRNO                  Byte     0001
  305.  CERRTYPE              Word     0002
  306.  DRIVE                  Byte     0004
  307.  READ_WR              Byte     0005
  308.  DISK_AREA              Byte     0006
  309.  RESP_MASK              Byte     0007
  310.  EXTERR                  Byte     0008
  311.  ECLASS                  Byte     0009
  312.  ACTION                  Byte     000A
  313.  LOCUS                  Byte     000B
  314.  NEXTDEV              Dword     000C
  315.  ATTR                  Word     0010
  316.  NXTFUNC              Word     0012
  317.  INTFUNC              Word     0014
  318.  DEVNAME              Byte     0016
  319.  DUMMY                  Byte     001E
  320. Turbo Assembler     Version 2.0        02/17/91 12:40:52        Page 7
  321. Symbol Table
  322. CRITERR.ASM
  323.  
  324.  
  325.  
  326. Groups & Segments          Bit Size Align  Combine Class
  327.  
  328. CRITERR_TEXT              16  00FE Word      Public  CODE
  329. DGROUP                  Group
  330.   _BSS                  16  0004 Word      Public  BSS
  331.   _DATA                  16  0020 Word      Public  DATA
  332.